package cn.deschen.biz.service.impl;

import cn.deschen.biz.constants.MsgConstants;
import cn.deschen.biz.domain.entity.MsgRecord;
import cn.deschen.biz.mapper.MsgRecordMapper;
import cn.deschen.biz.service.MsgRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author deschen
 * @since 2023-03-14
 */
@Service
public class MsgRecordServiceImpl extends ServiceImpl<MsgRecordMapper, MsgRecord> implements MsgRecordService {

    @Autowired
    private MsgRecordMapper recordMapper;

    @Override
    public void sendToData(String msgId, String content) {
        MsgRecord record = new MsgRecord();
        record.setMsgId(msgId);
        record.setMsgContent(content);
        record.setSendStatus(MsgConstants.Status.UNSEND);
        save(record);
    }

    @Override
    public void remarkSendSuccess(String msgId) {
        recordMapper.remarkSendStatus(msgId, MsgConstants.Status.SEND_SUCCESS, "");
    }

    @Override
    public void remarkSendError(String msgId, String exception) {
        recordMapper.remarkSendStatus(msgId, MsgConstants.Status.SEND_SUCCESS, exception);
    }

    @Override
    public void remarkConsumerSuccess(String msgId) {
        recordMapper.remarkConsumerStatus(msgId, MsgConstants.Status.CONSUMER_SUCCESS, "");
    }

    @Override
    public void remarkConsumerError(String msgId, String exception) {
        recordMapper.remarkConsumerStatus(msgId, MsgConstants.Status.CONSUMER_ERROR, exception);
    }
}
